#include <iostream>
#include <iomanip>
#include <thread>  // 用于延迟控制
#include <chrono>  // 用于延迟控制
using namespace std;

// 倒计时器类
class countdown {
public:
    countdown(int min, int sec) : m_min(min), m_sec(sec) {}
public:
    void set(int min, int sec);  // 设置初始时间
    countdown run();  // 运行
    countdown operator--();  // --i，前置形式
    countdown operator--(int);  // i--，后置形式
    friend ostream& operator<<(ostream&, const countdown&);
    bool is_zero() const;  // 判断时间是否归零
private:
    int m_min;  // 分钟
    int m_sec;  // 秒钟
};

void countdown::set(int min, int sec) {
    m_min = min;
    m_sec = sec;
}

countdown countdown::run() {
    if (m_sec == 0) {
        if (m_min > 0) {
            m_min--;
            m_sec = 59;
        }
    } else {
        m_sec--;
    }
    return *this;
}

countdown countdown::operator--() {
    return run();
}

countdown countdown::operator--(int n) {
    countdown c = *this;
    run();
    return c;
}

ostream& operator<<(ostream& out, const countdown& c) {
    out << setfill('0') << setw(2) << c.m_min << ":" << setw(2) << c.m_sec;
    return out;
}

bool countdown::is_zero() const {
    return (m_min == 0 && m_sec == 0);
}

int main() {
    int min, sec;
    cout << "Please enter the countdown time in minutes and seconds (for example, 1 30 means 1 minute and 30 seconds):"<<endl;
    cin >> min >> sec;

    countdown c(min, sec);  // 初始化倒计时

    while (!c.is_zero()) {  // 当时间未归零时继续循环
        cout << "time to left: " << c << endl;  // 输出当前时间
        c--;  // 减少时间
        this_thread::sleep_for(chrono::seconds(1));  // 延迟 1 秒
    }

    cout << "time over！" << endl;  // 倒计时结束

    return 0;
}